{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle\n",
    "import numpy as np\n",
    "import os\n",
    "\n",
    "CIFAR_DIR = \"./../../cifar-10-batches-py\"\n",
    "print(os.listdir(CIFAR_DIR))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(os.path.join(CIFAR_DIR, \"data_batch_1\"), 'rb') as f:\n",
    "    data = pickle.load(f, encoding='bytes')\n",
    "    print(type(data))\n",
    "    print(data.keys())\n",
    "    print(type(data[b'data']))\n",
    "    print(type(data[b'labels']))\n",
    "    print(type(data[b'batch_label']))\n",
    "    print(type(data[b'filenames']))\n",
    "    print(data[b'data'].shape)\n",
    "    print(data[b'data'][0:2])\n",
    "    print(data[b'labels'][0:2])\n",
    "    print(data[b'batch_label'])\n",
    "    print(data[b'filenames'][0:2])\n",
    "\n",
    "# 32 * 32 = 1024 * 3 = 3072\n",
    "# RR-GG-BB = 3072\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "image_arr = data[b'data'][100]\n",
    "image_arr = image_arr.reshape((3, 32, 32)) # 32 32 3\n",
    "image_arr = image_arr.transpose((1, 2, 0))\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.pyplot import imshow\n",
    "%matplotlib inline\n",
    "\n",
    "imshow(image_arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
